#include "mylabel.h"
#include <QDebug>
#include <QMouseEvent>
#include <QWheelEvent>
MyLabel::MyLabel(QWidget *parent) : QLabel(parent)
{

}

void MyLabel::enterEvent(QEvent *event)
{
    qDebug() << "鼠标进入";
}

void MyLabel::mousePressEvent(QMouseEvent *ev)
{
    if(ev->button() == Qt::LeftButton)
    {
        //Qt中的格式化字符串
        QString str1 = QString("鼠标左键 x = %1,y = %2").arg(ev->x()).arg(ev->y());
        qDebug() << str1.toUtf8().data();
    }
    if(ev->button() == Qt::RightButton)
    {
        //globalx,globaly为基于屏幕的坐标
        QString str = QString("鼠标右键 x = %1,y = %2").arg(ev->globalX()).arg(ev->globalY());
        qDebug() << str.toUtf8().data();
    }
}

void MyLabel::mouseReleaseEvent(QMouseEvent *ev)
{
    if(ev->button() == Qt::LeftButton)
    {
        qDebug() << "鼠标左键被释放";
    }
}

void MyLabel::mouseDoubleClickEvent(QMouseEvent *ev)
{
    if(ev->button() == Qt::LeftButton)
    {
        qDebug() << "鼠标左键被双击";
    }
}

void MyLabel::wheelEvent(QWheelEvent *ev)
{
    static int x = 0;
    x += ev->delta();//120
    if(ev->delta() > 0 )
    {
        qDebug() << "滚轮往前";
    }
    else
    {
        qDebug() << "滚轮往后";
    }
}

